package cn.gzsxt.music.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.gzsxt.music.mapper.SingerMapper;
import cn.gzsxt.music.query.SingerQueryObject;
import cn.gzsxt.music.service.SingerService;

@Service
public class SingerServiceImpl implements SingerService {
	
	@Autowired
	private SingerMapper mapper;
	
	@Override
	public Map<String, Object> selectSingerDataByCondition(SingerQueryObject qo) {
				
		Map<String,Object> datagirdMap = new HashMap<>();
		//查询总数
		datagirdMap.put("total", mapper.selectSingerTotalByCondition(qo));
		//查询结果集
		datagirdMap.put("rows", mapper.selectSingerListByCondition(qo));
		
		return datagirdMap;
	}
	
	
	@Override
	public int saveSinger(Map<String, Object> params) {		
		try {
			Map<String, Object> power = mapper.checkExistsSingerAction(params);
			if (power == null) {
				return mapper.insert(params);
			} else {
				return 2;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}		
		return 0;
	}

	@Override
	public int updateSinger(Map<String, Object> params) {
		try {
			Map<String, Object> power = mapper.checkExistsSingerAction(params);
			if(power == null) {
				return mapper.update(params);
			}else {				
				return 2;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 0;
	}

	@Override
	public int deleteSingerById(Long singer_id) {
		
		return mapper.deleteSingerById(singer_id);		
	}






	

	
	
}
